<?php

include_once("config.php");
$Access = $facebook->_getUserAccess();
die($Access);
if ($fbuser) {

    $user_profile = $facebook->api('/me');
    //////List user groups details using Facebook Query Language (FQL)
    //$fql_query = 'SELECT gid FROM group_member WHERE uid='.$fbuser.'';
	$fql_query = 'SELECT uid FROM page_fan WHERE page_id = 112557305523025';
	
	
    ////
    //////FQL query to list only groups where user is administrator.(administrator='true')
    //////$fql_query = 'select gid, name from group where gid IN (SELECT gid FROM group_member WHERE uid='.$fbuser.' AND administrator=\'true\')';
    $postResults = $facebook->api(array( 'method' => 'fql.query', 'query' => $fql_query ));
    ////
	echo "<pre>";
	die(print_r($postResults));
	
	//$dr = 'https://graph.facebook.com/705363646179647/members?access_token=CAAIAZAPOZAkrsBAFCZBHyAIm4SOmCU9BZARIMWdIZAZA9ZAYLe70IDFmnp7ZBk3ScFq9bB87ZANk451WJvQjokJSZATCoVjze45wD2KCAu7gqbrXbaeqJuDjnWqAleL8LnF9ZA6VZBhXlH7PCMLGog6ZBiqsoybw4ZCskEL3ooMrVelIj5tdsRO3IC8XFTD7xpvoy5257izLwO6kyBb9bgapADlniO';
	
	//$echo = json_decode(file_get_contents($dr));
	
	
	$i=1;
	$fc = '';
	foreach($postResults AS $le=>$el)
	{
		$gid = $el['gid'];
		$echo = json_decode(file_get_contents('https://graph.facebook.com/'.$gid.'/members?access_token='.$Access));
		foreach($echo->data AS $let=>$tel)
		{
			echo "<pre>";
			print_r('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />STT:'.$i."\n".'Name:'.$tel->name."\n".'UID:'.$tel->id);$i++;
			$fc .= $tel->id."\n";
		}
	}
	file_put_contents('list.txt', $fc);
	die();
	}else{
	 $loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
	 header('Location: ' . $loginUrl);
	}//$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
	 //header('Location: ' . $loginUrl);
	 //die(print_r($fbuser));

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Post to user Group Wall</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>

<div class="fbgroupwrapper">
<div id="fbgroupform" class="groupform">
<form id="form" name="form" method="post" action="process.php">
<label>Message
<span class="small">Link:</span>
</label>
<input type="text" name="link" value="" />
<label>Message
<span class="small">Nội dung</span>
</label>
<textarea name="message"></textarea>

<button type="submit" class="button" id="submit_button">Post Message</button>
<div class="spacer"></div>
</form>
</div>
</div>
</body>
</html>


</body>
</html>
